package cn.cmvideo.xworld.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import cn.cmvideo.xworld.R;

public class FeedbackActivity extends BaseActivity {
	private EditText editText = null;
	private TextView tip = null;
	private TextView textnumber = null;

	@Override
	public void doCreate() {
		this.setContentView(R.layout.feedback);
		this.curActivity = FeedbackActivity.this;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		editText = (EditText) findViewById(R.id.edittext);
		tip = (TextView) findViewById(R.id.tip);
		textnumber = (TextView) findViewById(R.id.textnumber);

		editText.addTextChangedListener(textWatcher);
	}

	@Override
	public void btnOnClick(View v) {
		if (v.getId() == R.id.returnBtn) {
			Intent intent = new Intent(FeedbackActivity.this,
					PersoncenteredActivity.class);
			startActivity(intent);
		} else {
			super.btnOnClick(v);
		}
	}

	private TextWatcher textWatcher = new TextWatcher() {
		@SuppressLint("UseValueOf")
		@Override
		public void onTextChanged(CharSequence s, int start, int before,
				int count) {
			if ((editText.getLineCount() + 1) * editText.getLineHeight() >= editText.getHeight()) {
				editText.setHeight(editText.getHeight()
						+ editText.getLineHeight());
			}
			if((editText.getLineCount() + 2) * editText.getLineHeight() < editText.getHeight()){
				editText.setHeight(editText.getHeight()
						- editText.getLineHeight());
			}
			if (s.length() == 0) {
				tip.setVisibility(View.VISIBLE);
			} else {
				tip.setVisibility(View.GONE);
			}
			textnumber.setText(new Integer(240 - s.length()).toString());
		}

		@Override
		public void beforeTextChanged(CharSequence s, int start, int count,
				int after) {

		}

		@Override
		public void afterTextChanged(Editable s) {

		}
	};
}
